package com.aspire.pams.tag.sichuan.tools.userInfo;

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * @author shuwei
 * 2012-09-20
 * 存储所有cmnet登录过程的用户信息和方法	
 */
@SuppressWarnings("serial")
public class UserInfo implements Serializable {
	
	//用户登录后的手机号
	private String mobile;
	//用户成功登录后boss分配的用户码
	private String login32Code;
	//记录用户登录前访问的地址，以便登录成功后跳转到该地址
	private String accessUrl;
	//用户登录失败次数
	private int loginFailCount;
	//用户登录过程用到的随机码
	private String randomCode;
	
	public String getAccessUrl() {
		return accessUrl;
	}
	public void setAccessUrl(String accessUrl) {
		this.accessUrl = accessUrl;
	}
	public int getLoginFailCount() {
		return loginFailCount;
	}
	public void setLoginFailCount(int loginFailCount) {
		this.loginFailCount = loginFailCount;
	}
	public String getRandomCode() {
		return randomCode;
	}
	public void setRandomCode(String randomCode) {
		this.randomCode = randomCode;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getLogin32Code() {
		return login32Code;
	}
	public void setLogin32Code(String login32Code) {
		this.login32Code = login32Code;
	}
	
	public static final int MOBILE = 0;
	public static final int LOGIN32CODE = 1;
	public static final int ACCESSURL = 2;
	public static final int LOGINFAILCOUNT = 3;
	public static final int RANDOMCODE = 4;
	
	public UserInfo set(int field, Object value){
		switch(field){
		case 0:
			this.setMobile((String)value);
			break;
		case 1:
			this.setLogin32Code((String)value);
			break;
		case 2:
			this.setAccessUrl((String)value);
			break;
		case 3:
			this.setLoginFailCount((Integer)value);
			break;
		case 4:
			this.setRandomCode((String)value);
			break;
		default:
			break;	
		}
		return this;
	}
	
	//检查用户是否是已经登录用户
	public boolean isLogin(){
		if(this.getMobile() != null && this.mobile.length() == 11 && 
				StringUtils.isNumeric(this.mobile) && this.getLogin32Code() != null && 
				this.getLogin32Code().length() == 32){
			return true;
		}
		return false;
	}
	
	public String toString(){
		return this.getMobile() + "|" + this.getLogin32Code() + "|" + this.getRandomCode() + 
		"|" + this.getLoginFailCount() + "|" + this.getAccessUrl();
	}
}